

<?php
$activeCategories = array();
foreach (Mage::helper('catalog/category')->getStoreCategories() as $child) {
    if ($child->getIsActive()) {
        $activeCategories[] = $child;
    }
}
$activeCategoriesCount = count($activeCategories);
$categoryInstance = Mage::getModel('catalog/category');
$categoryHtml = '';
$selectHtml = '';
$selectHtml .= '<select name="price-list" id="price-list">';
foreach( $activeCategories as $category){

    // get all children
    if (Mage::helper('catalog/category_flat')->isEnabled()) {
        $children = (array)$category->getChildrenNodes();
        $childrenCount = count($children);
    } else {
        $children = $category->getChildren();
        $childrenCount = $children->count();
    }
    $hasChildren = ($children && $childrenCount);

    // select active children
    $activeChildren = array();
    foreach ($children as $child) {
        if ($child->getIsActive()) {
            $activeChildren[] = $child;
        }
    }
    //$url = $categoryInstance->setData($category->getData())->getUrl();
    $url = Mage::getUrl('*/*/print',array('id'=>$category->getId()));
    $activeChildrenCount = count($activeChildren);

    $selectHtml .= '<option value="'.$category->getId().'">'.$category->getName().'</option>';
    if($activeChildrenCount >0){
        $categoryHtml .= '<ul class="mar_t2"><li><span>'.$category->getName().'</span>';
        $categoryHtml .='<ul class="mar_t1" style="padding-left:5px;">';
        $i =0;
        foreach($activeChildren as $subcategory){
            $i++;
            if($i==11){
                // $categoryHtml .='<li><a href="'.$url.'">view all</a></li>';                     
            }
            //$suburl = $categoryInstance->setData($subcategory->getData())->getUrl();


            // get all children
            if (Mage::helper('catalog/category_flat')->isEnabled()) {
                $children = (array)$subcategory->getChildrenNodes();
                $childrenCount = count($children);
            } else {
                $children = $subcategory->getChildren();
                $childrenCount = $children->count();
            }
            $hasChildren = ($children && $childrenCount);

            // select active children
            $subactiveChildren = array();
            foreach ($children as $child) {
                if ($child->getIsActive()) {
                    $subactiveChildren[] = $child;
                }
            }
            $activeChildrenCount = count($subactiveChildren);

            if($activeChildrenCount>0){
                $categoryHtml .='<li>'.$subcategory->getName().'';
            }else{
                $suburl = Mage::getUrl('*/*/view',array('id'=>$subcategory->getId()));
                $categoryHtml .='<li><a target="_blank" href="'.$suburl.'" title="'.$subcategory->getName().'" >'.$subcategory->getName().'</a>';
            }
            $selectHtml .= '<option value="'.$subcategory->getId().'">¦&nbsp;&nbsp;&nbsp;&nbsp;'.$subcategory->getName().'</option>';
            if($activeChildrenCount>0){
                $categoryHtml.='<ul class="mar_t3" style="padding-left:10px;">';
                foreach($subactiveChildren as $subcategorySub){
                    $categoryHtml .='<li><a target="_blank" href="'. Mage::getUrl('*/*/view',array('id'=>$subcategorySub->getId())).'">'.$subcategorySub->getName().'</a></li>'; 
                    $selectHtml .= '<option value="'.$subcategorySub->getId().'">¦&nbsp;&nbsp;&nbsp;&nbsp;¦&nbsp;&nbsp;&nbsp;&nbsp;'.$subcategorySub->getName().'</option>';
                }
                $categoryHtml .=' </ul>';
            }
            $categoryHtml .=' </li>';



        }
        $categoryHtml .= '</ul>';
        $categoryHtml .= '</li></ul>';

    }


}
$selectHtml .= '</select>';
//echo $selectHtml;
//echo $categoryHtml;
?>


    <div class="fieldset">
        <h2 class="legend">
&nbsp;&nbsp;&nbsp;&nbsp;Download price list
       </h2>

       <table cellspacing="2" cellpadding="2" border="0" style="margin:20px 10px">
<tbody><tr>
    <td style="padding: 0 10px"><b>Choose the category:</b></td>
    <td>
<?php echo $selectHtml;?>	
    </td>
    <td>
<table cellspacing="0" cellpadding="0" border="0">
<tbody><tr>
    <td width="11px"></td>
    <td nowrap="nowrap" align="center" class="button" >
        &nbsp;  <button type="button" title="<?php echo $this->__('Download') ?>" style="margin-right:10px" class="button btn-continue" onclick="setLocation('<?php echo $this->getUrl('productview/index/view') ?>'+'id/'+$('price-list').options[$('price-list').selectedIndex].value)"><span><span><?php echo $this->__('Download') ?></span></span></button>&nbsp;</td>
    <td width="9px"></td>
</tr>
</tbody></table>
    </td>
</tr>
</tbody></table>

    </div>


